﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class KNANGNNGUDAO:IData<KNANGNNGU> 
 	{
		public KNANGNNGUDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref KNANGNNGU item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + KNANGNNGU.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_KNANGNNGU", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + KNANGNNGU.c_MANV, item.MANV), new SqlParameter("@" + KNANGNNGU.c_MANN, item.MANN),
				 new SqlParameter("@" + KNANGNNGU.c_TDNN, item.TDNN), new SqlParameter("@" + KNANGNNGU.c_NNID, item.NNID),
				 new SqlParameter("@" + KNANGNNGU.c_NVID, item.NVID));
			if(t == 0)
				item.ID = Convert.ToInt32(obj);
			return i;
		}

		public override KNANGNNGU GetItem(IDataReader dr)
		{
			KNANGNNGU obj = new KNANGNNGU();
			obj.ID = Convert.ToInt32(dr[KNANGNNGU.c_ID]);
			obj.MANV = Convert.ToInt32(dr[KNANGNNGU.c_MANV]);
			obj.MANN = Convert.ToString(dr[KNANGNNGU.c_MANN]);
			obj.TDNN = Convert.ToString(dr[KNANGNNGU.c_TDNN]);
			obj.NNID = Convert.ToInt32(dr[KNANGNNGU.c_NNID]);
			obj.NVID = Convert.ToInt32(dr[KNANGNNGU.c_NVID]);
			return obj;
		}

		public override List<KNANGNNGU> GetAll()
		{
			return GetAll("sp_GetAllKNANGNNGU", CommandType.StoredProcedure);
		}

		public override KNANGNNGU GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt32(id));
		}
		public override KNANGNNGU GetItemById(KNANGNNGU item){
			throw new NotImplementedException();
		}

	}

 }
